package com.sample.kokou;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PersonListAdapter extends ArrayAdapter<Person> {
    private Activity context;
    
    public PersonListAdapter(Activity context, List<Person> people) {
    	super(context, R.layout.list_person, people);
        this.context = context;
    }

    @Override
    public long getItemId(int position) {
        return getItem(position).id;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Person person = getItem(position);

        LayoutInflater inflater = context.getLayoutInflater();
        convertView = inflater.inflate(R.layout.list_person, null);
        TextView nameView = GenericUtil.getView(convertView, R.id.name);
        TextView ageView = GenericUtil.getView(convertView, R.id.age);
        nameView.setText(person.getName());
        ageView.setText(String.format("%02d", person.getAge()));

        return convertView;
    }

}
